import {createAsyncThunk, createSlice} from "@reduxjs/toolkit";
import {getHomeGoodPriceData} from "@/services/modules/home";

export const fetchHomeDataAction = createAsyncThunk('fetchData',
    async (dispatch, getState) => {
        return await getHomeGoodPriceData();
    }
)

const homeSlice = createSlice({
    name: 'home',
    initialState: {
        goodPriceInfo: []
    },
    reducers: {
        changeGoodPriceInfoAction(state, action) {
            state.goodPriceInfo = action.payload;
        }
    },
    extraReducers: (builder) => {
        builder.addCase(fetchHomeDataAction.fulfilled, (state, action) => {
            state.goodPriceInfo = action.payload;
        })
    },

})

export const {changeGoodPriceInfoAction} = homeSlice.actions;
export default homeSlice.reducer;